export default{
    name:'lotterDollmachine',
    data() {
        return {
            readyFlag: false,
            btnClicked: false,
            giftBox: {
            show: false,
            showIndex: 6
            },
            num: 1,
            prizeIndex: 0,
            goActive:true,
            claws:{
              wrapperClass:'clawsHorizontalMove',//'clawsVerticalMove'
              wrapperStyle:'',
              leftClass:'',
              rightClass:''
            },
            styleVar:' --poleDis: 350rpx '
      }
    },
      
    methods: {
      showRuleCover() {
        var that = this;
        this.ruleObj.show = true;
        this.ruleObj.isIndex = false;
        that.$refs.ruleCover.showRuleCover();
      },
      getInit() {
        console.log("getInit")
        //设置杆子下移的距离
        // #ifdef H5
        let desk = document.getElementById("desk").getBoundingClientRect();
        let deskDistance = desk.top-30;
        this.styleVar='--poleDis:'+deskDistance + 'px'
        // #endif
        // #ifdef MP-WEIXIN
        wx.createSelectorQuery().in(this).select("#desk").boundingClientRect(rect=>{
          let deskDistance = rect.top-30;
          this.styleVar='--poleDis:'+ deskDistance + 'px'
          console.log("styleVar:",this.styleVar)
        }).exec()
        // #endif
      },
      go() {//点击爪子
        var that = this;
        if (!that.num) {
          uni.showModal({
            content: "没有抽奖次数啦",
            showCancel: false,
          });
          return;
        }
        if (that.btnClicked) {
          return;
        }
        this.goActive= false;
        that.btnClicked = true;
        that.num--;
        let clawsWrapper
        let posLeft
        let times=1;
        //爪子运动和页面跳转
        // #ifdef H5
         clawsWrapper = document.getElementById("clawsWrapper")
         posLeft = clawsWrapper.getBoundingClientRect().left;
        //  times = window.innerWidth/375;
         this.claws.wrapperStyle ='position:absolute;left:'+posLeft+'px';
        // #endif

        // #ifdef MP-WEIXIN
        console.log('Mp-weixin')
         wx.createSelectorQuery().in(this).select("#clawsWrapper").boundingClientRect(rect => {
          posLeft = rect.left
          this.claws.wrapperStyle ='position:absolute;left:'+posLeft+'px';
        }).exec()
        //  times = wx.getStorageInfoSync().windowWidth/375;
        // #endif
        this.claws.wrapperClass ='clawsVerticalMove';
        
        setTimeout(() => {
          that.claws.leftClass='close'
            that.claws.rightClass='close'
        }, 1000);

        setTimeout(() => {
          that.giftBox.show = true;
          if (posLeft < 55.75*times) {
            that.giftBox.showIndex = 1;
          } else if (posLeft < 90*times) {
            that.giftBox.showIndex = 2;
          } else if (posLeft < 120*times) {
            that.giftBox.showIndex = 3;
          } else if (posLeft < 178.876*times) {
            that.giftBox.showIndex = 4;
          } else if (posLeft < 295.75*times) {
            that.giftBox.showIndex = 5;
          }
        }, 2000);
        setTimeout(()=>{
          uni.showModal({
            content: "前往领取页面",
            showCancel: false,
          });
        },4000)
      },
    },

  mounted(){
    console.log("mounted")
    this.getInit()
  }
}